$(function(){
    $("#searchSafeCap_dategrid").datagrid_init;
    /*==初始化表格*/
    $('#searchSafeCap_dategrid').datagrid({
        loadMsg : "数据加载中",
        emptyMsg : "数据加载完成,当前无数据!",
        border:false,
        fit : true,
        title : "未戴安全帽记录时间表",
        fitColumns : true,
        pagination : true,
        rownumbers : true,
        singleSelect : true,
        // toolbar:"#searchSafeCap_dategrid_toolbar",
        columns : [ [
            {field : 'id',				title : '主键',			width:50 , align:'center',hidden:true},
            {field : 'cameraip',				title : '摄像头',			width:50 , align:'center',hidden:false,
                formatter: function(value,row,index){
                    return 	value;
                }
            },
            {field : 'datetime',			title : '时间 ',		width:50 , align:'center',hidden:false,
                formatter: function(value,row,index){
                    return 	value;
                }
            },
            {field : 'imgpath',title : '图片',	width : 30,align : 'center',hidden : false,
                formatter: function(value,row,index){
                    return 	'<a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="getImageWindow('+value+')">查看</a>';
                }
            }
        ] ],
        onLoadSuccess:function(data){
            $(this).datagrid('doCellTip',{'max-width':'300px','delay':500});
        }
    });

    var params = {};
    $("#searchSafeCap_dategrid").datagrid_pagination(basepath+"/user/v1/selectSafeCapList",JSON.stringify(params),"","" );

    /*查询按钮*/
    /*$("#searchSafeCap_btn_search").linkbutton({
        onClick:function(){
            var name = $("#searchSafeCap_Name").textbox("getValue");
            var datebegin=$.trim($("#searchSafeCap_DateBegin").datetimebox('getValue'));
            var dateend=$.trim($("#searchSafeCap_DateEnd").datetimebox('getValue'));
            var params = {};
            params.name = name;
            params.datebegin = datebegin;
            params.dateend = dateend;
            $("#searchSafeCap_dategrid").datagrid_pagination(basepath+"/user/v1/selectSafeCapList",JSON.stringify(params),"","" );
        }
    });*/

    loadPersonSourceCountHichart();

});

/**
 * 加载柱状图
 */
function loadPersonSourceCountHichart(){
   var params = {};
    $.ajax({
        type : "post",
        url : basepath + '/user/v1/selectSafeCatCount',
        dataType : "json",
        contentType : "application/json;charset=utf-8;",
        data : JSON.stringify(params),
        success : function(data) {
            if(data.result == "0"){
                $.messager.alert("提示","系统异常,请联系管理员!"+data.msg,"error");
                return;
            }
            console.dir(data);
            var rows = data.rows;
            if(rows == null || rows.length == 0){
                return;
            }
            var normalAll = [];
            var xname = [];
            for (var i = 0; i < rows.length; i++) {
                var normal = [];
                normal[0] = rows[i].cameraip;
                normal[1] = rows[i].count;
                normalAll[i]=normal;
                xname[i]="摄像头"+rows[i].cameraip;
            }

            //加载highcharts
            $('#searchSafeCap_personChart').highcharts({
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                title: {
                    text: '安全帽佩戴检测图'
                },
                xAxis: {
                    categories: xname,
                    crosshair: true
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: '未戴安全帽次数'
                    }
                },
                credits: {
                    enabled: false
                    // text: 'Example.com',
                    // href: 'http://www.example.com'
                },
                tooltip: {
                    headerFormat: '<span style="font-size:10px">摄像头{point.key}</span><table>',
                    pointFormat: '<tr><td style="color:{series.color};padding:0">未戴安全帽次数: </td>' +
                    '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
                    footerFormat: '</table>',
                    shared: true,
                    useHTML: true
                },
                plotOptions: {
                    column: {
                        pointPadding: 0.2,
                        borderWidth: 0
                    }
                },
                series: [{
                    type: 'column',
                    name: '安全帽佩戴检测图',
                    data : normalAll
                }]
            });

        }
    });


}
	